//配置路由
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
//引入路由组件
import Home from '../pages/Home/Home'
import Login from '../pages/Login'
import Search from '../pages/Serach'
import Regisit from '../pages/Register'

// 先把VueRouter原型对象的push，先保存一份
let originPush = VueRouter.prototype.push;
let originplace = VueRouter.prototype.place;
// 重写push函数
VueRouter.prototype.push = function(location,resolve,reject){
    if(resolve && reject){
        // call 和apply 区别
        // 相同点：都可以调用函数一次，都可以篡改函数的上下文一次
        // 不同点：call 与apply 传递参数：call传递参数用逗号隔开，apply方法执行，传递数组
        originPush.call(this, location, resolve, reject)
    }else {
        originPush.call(this,location, ()=>{},()=>{})
    }
}
VueRouter.prototype.place = function(location, resolve, reject){
    if(resolve && reject){
        originplace.call(this,location,resolve,reject)
    }else{
        originplace.call(this,location,()=>{},()=>{})
    }
}
export default new VueRouter({
    routes:[
        {
            path: '/home',
            component: Home,
            // 路由元信息
            meta:{
                show:true
            }
        },
        {
            path: '/login',
            component: Login,
            meta:{
                show:true
            }
        },
        {
            path: '/register',
            component: Regisit,
            meta:{
                show:true
            }
        },
        {
            // 经行路由占位
            path: '/search',
            component: Search,
            meta:{
                show:true
            },
            name: 'search',
        },
        // 重定向：在项目跑起来的时候，访问/ ，立马让他定向到首页
        {
            path:'*',
            redirect:'/home'
        }
    ]
})